package com.focusai.efairy.ui.adapter.dev;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.focusai.efairy.R;
import com.focusai.efairy.model.dev.DeviceRealTimeDataItem;
import com.focusai.efairy.utils.DateUtils;
import com.focusai.efairy.utils.PrUtils;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by luo_guangwen on 2017/8/30.
 */

public class DeviceInfoCidRealViewBinder extends ItemViewBinder<DeviceRealTimeDataItem, DeviceInfoCidRealViewBinder.ViewHolder> {

    private Context mContext;

    public DeviceInfoCidRealViewBinder(Context mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_dev_cid, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull DeviceRealTimeDataItem dataItem) {
        if (dataItem.cid == 0) {
            if (dataItem.localType == 1) {
                holder.tvLable.setText("心跳间隔");
                holder.tvRealData.setText(dataItem.st + "s");
            } else if (dataItem.localType == 2) {
                holder.tvLable.setText("音响模式");
                if (dataItem.rtv == 0x01) {
                    holder.tvRealData.setText("正常");
                } else {
                    holder.tvRealData.setText("静音");
                }
            } else if (dataItem.localType > 10000) {
                holder.tvLable.setText(R.string.update_data_time);
                holder.tvRealData.setText(DateUtils.getSimpleCurrentDate3(dataItem.localType * 1000L));
            }
        } else {
            String text = PrUtils.getNameByPt(dataItem.pt) + "通道" + dataItem.cid;
            if (dataItem.pt == 128) {
                holder.tvRealData.setText(PrUtils.getInJianCeStateByRtv(dataItem.rtv) + " / " + PrUtils.getInJianCeStateByHtv(dataItem.thv));
                if (dataItem.cid == 9){
                    text="烟感探测1";
                }else if (dataItem.cid == 10){
                    text="气体探测2";
                }
            } else if (dataItem.pt == 129) {
                holder.tvRealData.setText(PrUtils.getOutJianCeStateByRtv(dataItem.rtv) + " / " + PrUtils.getOutJianCeStateByHtv(dataItem.thv));
            } else {
                String unitByPt = PrUtils.getUnitByPt(dataItem.pt);
                float rateByPt = PrUtils.getRateByPt(dataItem.pt);
                holder.tvRealData.setText(PrUtils.getRountByPt(dataItem.rtv * rateByPt, dataItem.pt)
                        + unitByPt + " / " + PrUtils.getRountByPt(dataItem.thv * rateByPt, dataItem.pt) + unitByPt);
            }
            holder.tvLable.setText(text);
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvLable;
        TextView tvRealData;

        ViewHolder(View itemView) {
            super(itemView);
            tvLable = (TextView) itemView.findViewById(R.id.tv_dev_cid_lable);
            tvRealData = (TextView) itemView.findViewById(R.id.tv_dev_cid_real);
        }

    }
}
